import { defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import legacy from '@vitejs/plugin-legacy';
const path = require('path');
const config = loadEnv('', process.cwd())
export default defineConfig({
  plugins: [
    react(),
    legacy({
      targets: [
        'ie >= 10',
        'Safari >= 10.1',
        'Firefox >= 54'
      ]
    })
  ],
  server: {
    host: '0.0.0.0',
    port: 3030,
    fs: {
      strict: false,
    },
    proxy: {
      '/api': {
        target: config.VITE_SERVER_TARGET,
        changeOrigin: true,
        secure: false
        // rewrite: (path) => path.replace(/^\/api/, '/')
      },
    },
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
      '~': path.resolve(__dirname),
    },
  },
  css: { modules: { localsConvention: 'camelCase' } },
  build: {
    rollupOptions: {
      output: {
        manualChunks: {
          'react': ['react', 'react-dom'],
          'lodash': ['lodash-es'],
          'echarts': ['echarts'],
          'moment': ['moment']
        }
      }
    },
    minify: 'terser',
    terserOptions: {
      compress: {
        //生产环境时移除console
        drop_console: true,
        drop_debugger: true,
      },
    },
  }
  // build: {
  //   minify: 'terser',
  //   terserOptions: {
  //     compress: {
  //       //生产环境时移除console
  //       drop_console: true,
  //       drop_debugger: true,
  //     },
  //   },
  // },
});
